#include <stdio.h> 
#include <time.h> 
#include <sys/time.h> 
#include <stdlib.h> 
#include <signal.h> 

int count = 0; 

void set_timer() 
{ 
    struct itimerval itv, oldtv; 
    itv.it_interval.tv_sec = 0; 
    itv.it_interval.tv_usec = 1000; 
    itv.it_value.tv_sec = 0; 
    itv.it_value.tv_usec = 1000; 
    setitimer(ITIMER_REAL, &itv, &oldtv); 
} 
void sigalrm_handler(int sig) 
{ 
    count++; 
} 
int main( ) 
{ 
    signal(SIGALRM, sigalrm_handler); 
    set_timer(); 
    while(count < 10000){ } 
    printf("count  = %d\n", count); 
    exit(0); 
}
